package com.controller.xsxt;

import com.entity.common.ApiResult;
import com.service.xsxt.SeasonService;
import com.entity.xsxt.Season;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by System on 2019/04/15 09:37:07.
 */
@RestController
@RequestMapping("season")
public class SeasonController {

    @Autowired
    private SeasonService seasonService;

    @RequestMapping("/getPageList")
    public Map<String,Object> getPageList(@RequestParam(value = "pager.pageNo",defaultValue ="1" )  Integer pageNum,
                @RequestParam(value = "pager.pageSize",defaultValue ="10" ) Integer pageSize,Season season){
        Map<String, Object> map=new HashMap<>();
        PageHelper.startPage(pageNum,pageSize);
        PageInfo<Season> pageInfo = new PageInfo<>(seasonService.getPageList(season));
        map.put("rows",pageInfo.getList());
        map.put("pager.totalRows", pageInfo.getTotal());
        map.put("pager.pageNo",pageNum);
        return  map;
    }

    @RequestMapping("/addSeason")
    public ApiResult addSeason(Season season){
        return seasonService.addSeason(season);
    }

    @RequestMapping("/deleteSeason")
    public ApiResult deleteSeason(Long id){
        return seasonService.deleteSeason(id);
    }

    @RequestMapping("/getSeasonById")
    public ApiResult getSeasonById(Long id){
        return seasonService.getSeasonById(id);
    }

    @RequestMapping("/editSeason")
    public ApiResult editSeason(Season season){
        return seasonService.editSeason(season);
    }

}
